////////////////////////////////////////////////////////////////////////////////

#ifndef _SERVERPACKETFACTORY_H_
#include "serverpacketfactory.h"
#endif

////////////////////////////////////////////////////////////////////////////////

#ifndef _CLIENTINPUTPACKETONSERVER_H_
#include "clientinputpacketonserver.h"
#endif

#ifndef _CLIENTINFOPACKETONSERVER_H_
#include "clientinfopacketonserver.h"
#endif

#ifndef _LOADER_H_
#include "loader.h"
#endif

////////////////////////////////////////////////////////////////////////////////


ServerPacketFactory::ServerPacketFactory()
{
}


////////////////////////////////////////////////////////////////////////////////


ClientPacketOnServer* ServerPacketFactory::ComposePacket( int _clientID, Buffer& _buffer )
{
    Packet::PacketCode code;
    _buffer.ReadMemory( &code, sizeof(Packet::PacketCode) );

    Loader loader(_buffer);

    switch (code)
    {
    case Packet::CLIENT_INPUT:
        {
            ClientInputPacket clientInputPacket = loader.LoadClientInputPacket();
            return new ClientInputPacketOnServer(_clientID, clientInputPacket);
        }
        
    case Packet::CLIENT_INFO:
        {
            ClientInfoPacket clientInfoPacket = loader.LoadClientInfoPacket();
            return new ClientInfoPacketOnServer(_clientID, clientInfoPacket);
        }

    default:
        throw "not implemented";
    }
}


////////////////////////////////////////////////////////////////////////////////
